def isPrime(num):
    if num <=1:
     return False 
    for i in range(2, num):
        if  num % i == 0:
             return False
    return True


    
num=int(input())
if 999<num<10000:
    a=num
    b=num//10
    c=num%1000
    d=num%100
    e=num%1000//10
    f=num//100
    g=num//1000
    h=num//100%10
    k=num//10%1000%100%10
    j=num%1000 %10
    mark=[a,b,c,d,e,f,g,h,k,j]
    stepanok=0
    for n in mark:
        if isPrime(n):
            stepanok=max(stepanok,n)
    print(stepanok)
else:
    print(0)

